#获取采购计划表
import json
from flask import request
from db_client import *

def get_plan():
        pur_num = request.args.get('search')
        results_tuple = mysql_client.get_plan(pur_num)
        plan_list = []
        results = []
        for rt in results_tuple:
                results.append(list(rt))
        for result in results:
                pm = result[6].split(',')
                result[6] = pm
                t = {
                        "item_name" : result[0],
                        "item_id" : result[1],
                        "plan_id" : result[2],
                        "count" : result[3],
                        "total_money" : result[4],
                        "state" : result[5],
                        "demand_ids" : result[6],
                        "create_date" : result[7],
                        "approval_date" : result[8],
                        "approval_staff_id" : result[9],
                        "unit_price" : result[10],
                        "supplier_id" : result[11]
                }
                plan_list.append(t)
        data = plan_list
        return json.dumps(data,ensure_ascii=False)